package com.ztgf.shopping.api.cms.shop;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.common.utils.StrUtils;
import com.ztgf.shopping.models.vo.shop.ShopBlacklistVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
import com.ztgf.shopping.models.service.shop.IShopBlacklistService;
import com.ztgf.shopping.models.bo.shop.ShopBlacklistSaveBO;
import com.ztgf.shopping.models.bo.shop.ShopBlacklistBO;
import com.ztgf.shopping.models.dto.shop.ShopBlacklistDTO;

/**
 * 黑名单控制器
 *
 * @author zhanghualang
 * @Date 2020-06-16 16:01:00
 */

@RestController
@RequestMapping("/cms/shopBlacklist")
@Slf4j
@Api(value = "ShopBlacklistController",tags = "黑名单接口")
public class ShopBlacklistController {

    @DubboReference
    private IShopBlacklistService shopBlacklistService;

//    @ApiOperation(value = "添加黑名单",notes = "添加黑名单")
//    @PostMapping(value = "/insert")
//    public Result insert(ShopBlacklistSaveBO saveBO) {
//        boolean flag = shopBlacklistService.add(saveBO);
//        if (flag){
//            return new Result<>();
//        } else {
//            return new Result<>(CodeEnum.FAIL_100007);
//        }
//    }
//
//    @PostMapping("/save")
//    @ApiOperation(value = "保存黑名单",notes = "保存黑名单")
//    public Result save(ShopBlacklistSaveBO saveBO){
//        if(saveBO.getId() == null){
//            //添加
//            return  insert(saveBO);
//        } else {
//            return  update(saveBO);
//        }
//    }
//
//    @ApiOperation(value = "修改黑名单",notes = "修改黑名单")
//    @PostMapping("/update")
//    public Result update(ShopBlacklistSaveBO saveBO){
//        ShopBlacklistDTO dto = new ShopBlacklistDTO();
//        BeanUtils.copyProperties(saveBO, dto);
//        dto.setId(saveBO.getId());
//        boolean flag = shopBlacklistService.updateById(dto);
//        if (flag){
//            return new Result<>();
//        } else {
//            return new Result<>(CodeEnum.FAIL_100008);
//        }
//    }


    @ApiOperation(value = "删除黑名单",notes = "删除黑名单")
    @ApiImplicitParam(name = "id",value = "黑名单id",required = true,paramType = "query",dataType = "Long")
    @PostMapping("/delete")
    public Result delete(@RequestParam("id") Long id){
        boolean flag = shopBlacklistService.deleteBlackById(id);
        if (flag){
            return new Result<>();
        } else {
            return new Result<>(CodeEnum.FAIL_100009);
        }
    }

    @PostMapping("/deleteBatch")
    @ApiOperation(value = "批量删除黑名单",notes = "批量删除黑名单")
    @ApiImplicitParam(name = "ids",value = "ids:以逗号隔开",required = true,paramType = "query", dataType = "String")
    public Result deleteBatch(@RequestParam("ids") String ids){
        if(StrUtils.isEmpty(ids)){
            return new Result(CodeEnum.FAIL_100002 );
        }
        shopBlacklistService.deleteBlackBatchIds(ids);
        return new Result<>();
    }

    @ApiOperation(value = "删除黑名单",notes = "删除黑名单")
    @ApiImplicitParam(name = "id",value = "黑名单id",required = true,paramType = "query",dataType = "Long")
    @PostMapping("/deleteById")
    public Result deleteById(@RequestParam("id") Long id){
        boolean flag = shopBlacklistService.deleteBlackList(id);
        if (flag){
            return new Result<>();
        } else {
            return new Result<>(CodeEnum.FAIL_100009);
        }
    }

    @PostMapping("/deleteBatchByIds")
    @ApiOperation(value = "批量删除黑名单",notes = "批量删除黑名单")
    @ApiImplicitParam(name = "ids",value = "ids:以逗号隔开",required = true,paramType = "query", dataType = "String")
    public Result deleteBatchByIds(@RequestParam("ids") String ids){
        if(StrUtils.isEmpty(ids)){
            return new Result(CodeEnum.FAIL_100002 );
        }
        shopBlacklistService.deleteBlackListBatchIds(ids);
        return new Result<>();
    }

//    @PostMapping("/get")
//    @ApiOperation(value = "根据id查找",notes = "根据id查找")
//    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
//    public Result<ShopBlacklistDTO> get(@RequestParam("id") Long id){
//        if(id == null){
//            return new Result<>(CodeEnum.FAIL_100002 );
//        }
//
//        ShopBlacklistDTO dto = shopBlacklistService.selectById(id);
//
//        return new Result<>(dto);
//    }


    /**
     * 根据有选择获取黑名单表
     * @return
     */
    @ApiOperation(value = "根据type用户获取店铺黑名单表",notes = "根据type获取用户或者店铺黑名单表")
    @PostMapping("/getListBySelect")
    public Result<Page<ShopBlacklistVO>> getListBySelect(ShopBlacklistBO shopBlacklistBO){
        if (shopBlacklistBO.getType() == null){
            return new Result<>(CodeEnum.FAIL_100002);
        }

        Page<ShopBlacklistVO> shopBlacklistVOPage = shopBlacklistService.getListBySelect(shopBlacklistBO);
        return new Result<>(shopBlacklistVOPage);
    }

}
